from musiclink.models import Genre,MidLink,MusicGenreLink
from google.appengine.api import memcache

GIL_KEY = "GENRE_INFO_LIST"
MC_TIME = 3600*12

###
# genre process
###
def get_genre_info_list():
    gil = memcache.get(GIL_KEY)
    if gil != None:
        return gil
    else:
        gil = get_genre_info_from_db()
        memcache.set(GIL_KEY,gil,MC_TIME)
        return gil

def update_genre_info_list():
    gil = get_genre_info_from_db()
    memcache.set(GIL_KEY,gil,MC_TIME)
    return gil

def get_genre_info_from_db():
    genre_list = []
    for g in Genre.all():
        genre_list.append({
            'key':g.key(),
            'name':g.name
            })
    return genre_list

###
# a new section
###
